package api;

import util.HttpClientUtil;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class EmpApi {
    public static String post_url="http://ihrm-test.itheima.net//api/sys/user";
    public static String query_url="http://ihrm-test.itheima.net/api/sys/user/%s";
    //新增员工
    public static ResponseData addEmp(String username,String mobile,String workNumber) throws IOException, URISyntaxException {
        Map<String,Object> data=new HashMap<>();
        data.put("username",username);
        data.put("mobile",mobile);
        data.put("workNumber",workNumber);
        return HttpClientUtil.post_json(post_url, null, data);
    }
    //查询员工
    public static ResponseData queryEmp(String EmpId) throws IOException, URISyntaxException {
        String format = String.format(query_url, EmpId);
        return HttpClientUtil.get(format,null);
    }
    //修改员工
    public static ResponseData putEmp(String name,String EmpId) throws IOException, URISyntaxException {
        String format = String.format(query_url, EmpId);
        Map<String,Object> data=new HashMap<>();
        data.put("username",name);
        return HttpClientUtil.put_json(format,null,data);
    }
    //删除员工
    public static ResponseData delete(String EmpId) throws IOException, URISyntaxException {
        String format = String.format(query_url, EmpId);
        return HttpClientUtil.delete(format,null);
    }

}
